<?php 
@session_start();
include "../include/config.php";
include "../include/db.php";

$query = "SELECT * FROM admin_usuarios_permiso_perfil WHERE id_rep_dep = 0";
$result = mysql_query($query) or trigger_error(mysql_error());

while ($row = mysql_fetch_array($result)) {
	$query2 = "SELECT * FROM vw_agentes WHERE legajo = {$row['id_usuario']} ";				
	$result2 = mysql_query($query2) or trigger_error(mysql_error());
	
	if($row2 = mysql_fetch_array($result2)){
		$query3 = 	"UPDATE admin_usuarios_permiso_perfil 
					SET
					id_rep_dep = {$row2['id_rep_dep']} 
					WHERE
					id_usuario = {$row['id_usuario']} AND id_rep_dep = 0";	
		$result3 = mysql_query($query3) or trigger_error(mysql_error());	
	}	
	
}

echo "LISTO";

?>